package com.gking.processHarvest.controller;


import com.gking.processHarvest.common.Res;
import com.gking.processHarvest.entity.Tag;
import com.gking.processHarvest.service.Tag.TagService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/tag")
public class TagController {

    @Autowired
    private TagService tagService;


    /**
     * 批量创建标签
     *
     * @param tags
     * @return
     */
    @PostMapping("/create")
    public Res<String> create(@RequestBody List<Tag> tags) {
        log.warn("传递过来的标签信息为：{}", tags);
        return tagService.create(tags);
    }


    /**
     * 修改标签信息
     *
     * @param tag
     * @return
     */
    @PutMapping("/update")
    public Res<String> update(@RequestBody Tag tag) {
        log.warn("传递过来的标签信息为：{}", tag);
        return tagService.update(tag.getId(), tag.getName(), tag.getColor());
    }


    /**
     * 删除标签
     *
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    public Res<String> delete(@PathVariable String id) {
        log.warn("要删除的标签 id 为：{}", id);
        return tagService.delete(id);
    }
}
